// page/person/index.js
var config = require('../../config.js');
var loadPerson = require('loadPerson.js');
var wxParse = require('../../wxParse/wxParse.js');
var app = getApp();
var userinfo_all = null;
var username = '';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    footerConfig: {
      User: true
    },
    nickName: '',
    url: '../images/tx.jpg',
    userinfo: null,
    historyId: 0,//播放记录
    collectionId: 0,//我的收藏,防止重复点击
    noticeId: 0,
    aboutId: 0,
  },
 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var INFO = wx.getStorageSync("INFO");//存放用户信息，若是存在，则不发送请求
    if (INFO.nickName) {
      that.setData({
        nickName: INFO.nickName,
        url: INFO.url
      });
    } else {
      app.getUserName(function (user_name) {
        loadPerson.load_userInfo(user_name, that);
      });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: config.shareDes,
      path: '/pages/index/index',
      imageUrl: '../images/sharepic_1.jpg'
    }
  }, qualityClick: function (e) {
    var that = this;
    wx.openSetting({
      success: function (data) {
        if (data) {
          if (data.authSetting["scope.userInfo"]) {
            app.getUserName(function (user_name) {
              loadPerson.load_userInfo(username, that);
            });
          }
        }
      }
    });
  }, play: function (e) {
    wx.reLaunch({
      url: '../index/index',
    })
  }, search: function (e) {
    wx.reLaunch({
      url: '../waterfall/waterfall',
    })
  }, user: function (e) {

  }, history: function (e) {
    var historyId = this.data.historyId + 1;
    if (historyId != 1) {
      return;
    }
    this.setData({
      historyId: historyId
    });
    wx.navigateTo({
      url: '../history/history',
    })
  }, collection: function (e) {
    var collectionId = this.data.collectionId + 1;
    if (collectionId != 1) {
      return;
    }
    this.setData({
      collectionId: collectionId
    });

    wx.navigateTo({
      url: '../collection/collection',
    })
  }, about: function (e) {
    var aboutId = this.data.aboutId + 1;
    if (aboutId != 1) {
      return;
    }
    this.setData({
      aboutId: aboutId
    });

    wx.navigateTo({
      url: '../about/about',
    })
  }, notice: function (e) {
    var noticeId = this.data.noticeId + 1;
    if (noticeId != 1) {
      return;
    }
    this.setData({
      noticeId: noticeId
    });

    wx.navigateTo({
      url: '../notice/notice',
    })
  }
})